package com.tm.orderserver.service.impl;

import com.tm.commonutils.dto.OrderDTO;
import com.tm.orderserver.entity.OrderEntity;
import com.tm.orderserver.service.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {

    Map<Long,OrderEntity>  map = new HashMap<>();
    @Override
    public OrderEntity findByOrderId(Long id) {
        return map.get(id);
    }

    @Override
    public List<OrderEntity> list() {
        List<OrderEntity> list = new ArrayList<>();
        list.add(new OrderEntity(1L,"订单1"));
        list.add(new OrderEntity(2L,"订单2"));
        return list;
    }

    @Override
    public void save(OrderDTO orderDTO) {
        OrderEntity order = new OrderEntity();
        BeanUtils.copyProperties(orderDTO,order);

        map.put(order.getId(),order);
    }

    @Override
    public void delByOrderId(Long id) {
        map.remove(id);
    }

    @Override
    public void updateById(OrderDTO orderDTO) {
        OrderEntity order = map.get(orderDTO.getId());
        order.setTitle(orderDTO.getTitle());
        map.put(orderDTO.getId(),order);
    }
}
